package controleur;

import java.io.File;

import javax.swing.filechooser.FileFilter;

public class MonFileFilter extends FileFilter
{
	private String	type;

	@Override
	public boolean accept(File file)
	{
		if(file.isDirectory())
		{
			return true;
		}
		String fileName = file.getName();
		int index = fileName.lastIndexOf('.');
		if(index > 0 && index < fileName.length() - 1)
		{
			String extension = fileName.substring(index + 1).toLowerCase();
			if(extension.equals(type))
			{
				return true;
			}
		}
		return false;
	}

	@Override
	public String getDescription()
	{
		if(type.equals("txt"))
		{
			return "TXT (*.txt)";
		}
		if(type.equals("m"))
		{
			return "MATLAB (*.m)";
		}
		if(type.equals("xls"))
		{
			return "EXCEL (*.xls)";
		}
		if(type.equals("xlsx"))
		{
			return "EXCEL 2007 (*.xlsx)";
		}
		if(type.equals("lp"))
		{
			return "CPLEX (*.lp)";
		}
		return("Format inconu (*." + type + ")");
	}

	public MonFileFilter(String type)
	{
		this.type = type;
	}
}
